package com.junzhiit.nengji.api.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.GoodsService;
import com.junzhiit.nengji.api.service.ShopService;
import com.junzhiit.nengji.api.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/goods")
public class GoodsController extends BaseController {

	@Autowired
	private GoodsService goodsService;
	
	@Autowired
	private ShopService  shopService;
	
	@ApiOperation(value = "根据商品名称查询商品")
	@Deprecated
	@RequestMapping(value = "/search", method = RequestMethod.GET)
	public ResultVO findGoods(String goodsName,String userId) {
		AssertUtil.notBlank(goodsName, "goodsName is required.");
		return goodsService.findGoods(goodsName, userId);
	}
	
	@ApiOperation(value = "根据商品名称查询商品(type==shop按照店铺查询)")
	@RequestMapping(value = "/search/type",method = RequestMethod.GET)
	public ResultVO findAllByType(String type,String name,String systemTypeId,String userId,Integer status){
		AssertUtil.notBlank(userId, "userId is required.");
		if("shop".equals(type)){
			return shopService.findShops(name, userId);
		}else{
			return goodsService.findGoodsBySystemType(name, systemTypeId,userId,status);
		}
	}
	
	@ApiOperation(value = "根据code查询商品详情")
	@Deprecated
	@RequestMapping(value = "/info", method = RequestMethod.GET)
	public ResultVO findGoodsInfo(String code,String userId) {
		AssertUtil.notBlank(code, "code is required.");
		AssertUtil.notBlank(userId, "userId is required.");
		return goodsService.findGoodsInfo(code,userId);
	}
	
	@ApiOperation(value = "根据code查询商品详情(带五星好评、优惠劵)")
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	public ResultVO findGoodsInfoNew(String code,String userId) {
		AssertUtil.notBlank(code, "code is required.");
		AssertUtil.notBlank(userId, "userId is required.");
		return goodsService.findGoodsInfoNew(code,userId);
	}
	
	@ApiOperation(value = "检验商品库存")
	@RequestMapping(value = "/check/stock", method = RequestMethod.GET)
	public ResultVO checkStock(String goodsInfo) {
		return goodsService.checkStock(goodsInfo);
	}
	
	@ApiOperation(value = "取得赠送VIP商品")
	@RequestMapping(value = "/give/vip", method = RequestMethod.GET)
	public ResultVO getVipGoodsList(){
//		return goodsService.getVipGoodsList();
		return null;
	}
}
